package com.nari.ruist.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.nari.common.log.annotation.Log;
import com.nari.common.log.enums.BusinessType;
import com.nari.common.security.annotation.PreAuthorize;
import com.nari.ruist.domain.RstRequest;
import com.nari.ruist.service.IRstRequestService;
import com.nari.common.core.web.controller.BaseController;
import com.nari.common.core.web.domain.AjaxResult;
import com.nari.common.core.utils.poi.ExcelUtil;
import com.nari.common.core.web.page.TableDataInfo;

/**
 * 请求实例主 Controller
 *
 * @author nari
 * @date 2021-04-02
 */
@RestController
@RequestMapping("/request")
public class RstRequestController extends BaseController {
    @Autowired
    private IRstRequestService rstRequestService;

    /**
     * 查询请求实例主 列表
     */
    @PreAuthorize(hasPermi = "system:request:list")
    @GetMapping("/list")
    public TableDataInfo list(RstRequest rstRequest) {
        startPage();
        List<RstRequest> list = rstRequestService.selectRstRequestList(rstRequest);
        return getDataTable(list);
    }

    /**
     * 导出请求实例主 列表
     */
    @PreAuthorize(hasPermi = "system:request:export")
    @Log(title = "请求实例主 ", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RstRequest rstRequest) throws IOException {
        List<RstRequest> list = rstRequestService.selectRstRequestList(rstRequest);
        ExcelUtil<RstRequest> util = new ExcelUtil<RstRequest>(RstRequest.class);
        util.exportExcel(response, list, "request");
    }

    /**
     * 获取请求实例主 详细信息
     */
    @PreAuthorize(hasPermi = "system:request:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(rstRequestService.selectRstRequestById(id));
    }

    /**
     * 新增请求实例主
     */
    @PreAuthorize(hasPermi = "system:request:add")
    @Log(title = "请求实例主 ", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RstRequest rstRequest) {
        return toAjax(rstRequestService.insertRstRequest(rstRequest));
    }

    /**
     * 修改请求实例主
     */
    @PreAuthorize(hasPermi = "system:request:edit")
    @Log(title = "请求实例主 ", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RstRequest rstRequest) {
        return toAjax(rstRequestService.updateRstRequest(rstRequest));
    }

    /**
     * 删除请求实例主
     */
    @PreAuthorize(hasPermi = "system:request:remove")
    @Log(title = "请求实例主 ", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(rstRequestService.deleteRstRequestByIds(ids));
    }
}
